Add PKCS8 parsing to support PEM ASN.1 Private Keys #708
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As described in issue #437, OpenSSH and other utilities support generating and storing private keys formatted using PKCS#8. The
PKCS8KeyFile
class uses the BouncyCastlePEMParser
, which returns aPrivateKeyInfo
object when reading a PEM file including the headerBEGIN PRIVATE KEY
. ThePKCS8KeyFile.readKeyPair()
method logs a debug message indicating thatPrivateKeyInfo
is not a supported object for parsing.This pull request adds a
KeyPairConverter
interface with a primary implementation supportingPrivateKeyInfo
objects returned fromPEMParser
. ThePrivateKeyInfoKeyPairConverter
delegates to specific implementations based on the Algorithm Object Identifier contained inPrivateKeyInfo
. Implementations support reading DSA, ECDSA, and RSA Private Keys, and determining the associated Public Key in order to return aPEMKeyPair
.This pull request includes unit test updates with sample private keys generated using the following
ssh-keygen
commands:ssh-keygen -t dsa -m PKCS8
ssh-keygen -t ecdsa -m PKCS8
ssh-keygen -t rsa -b 2048 -m PKCS8
Classes included in this pull request should also provide the foundation for an additional implementation that supports reading encrypted private keys.